package com.fqcar.fqdf.util;

import android.content.Context;
import android.widget.Toast;

import com.afollestad.materialdialogs.MaterialDialog;
import com.fqcar.fqdf.R;
import com.fqdf.framework.android.util.AndroidUtils;

public class DialogUtil {
    /**
     * 弹出Toast消息
     *
     * @param msg
     */
    public static void ToastMessage(Context con, String msg) {
        Toast.makeText(con, msg, Toast.LENGTH_SHORT).show();
    }

    /**
     * 弹出Toast消息
     *
     * @param con 上下文内容
     * @param msg 消息资源id
     */
    public static void ToastMessage(Context con, int msg) {
        Toast.makeText(con, msg, Toast.LENGTH_SHORT).show();
    }

    /**
     * 创建显示进度处理的dialog
     *
     * @param context
     * @param title
     * @param content
     * @return
     */
    public static MaterialDialog createProgressDialog(Context context, String title, String content) {
        return createProgressDialog(context, title, content, false);
    }

    public static MaterialDialog createDefaultProgressDialog(Context context, String content) {
        return createProgressDialog(context, null, content, true);
    }

    public static MaterialDialog createDefaultProgressDialogNoCancel(Context context, String content) {
        return createProgressDialog(context, null, content, false);
    }

    /**
     * 创建禁止取消的提交等待框
     *
     * @param context
     * @return
     */
    public static MaterialDialog createNoCancelSubmit(Context context) {
        return createProgressDialog(context, null, context.getString(R.string.is_submit), false);
    }
    /**
     * 创建加载等待框
     *
     * @param context
     * @return
     */
    public static MaterialDialog createLoadingDialog(Context context) {
        return createProgressDialog(context, null, context.getString(R.string.is_loading), true);
    }
    /**
     * 创建加载等待框--不可取消
     *
     * @param context
     * @return
     */
    public static MaterialDialog createNoCancelLoadingDialog(Context context) {
        return createProgressDialog(context, null, context.getString(R.string.is_loading), false);
    }

    /**
     * 创建上传图片--不可取消
     *
     * @param context
     * @return
     */
    public static MaterialDialog createNoCancelUploadImgDialog(Context context) {
        return createProgressDialog(context, null, context.getString(R.string.upload_iamge), false);
    }

    /**
     * @param context
     * @param title
     * @param content
     * @param cancel
     * @return
     */
    public static MaterialDialog createProgressDialog(Context context, String title, String content, boolean cancel) {
        return new MaterialDialog.Builder(context)
                .title(title)
                .content(content)
                .progress(true, 0)
                .widgetColorRes(R.color.a)
                .canceledOnTouchOutside(cancel)
                .cancelable(cancel).build();
    }

    public static void hideIndeterminateProgress(MaterialDialog dialog) {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    public static void showIndeterminateProgress(MaterialDialog dialog) {
        if (dialog != null && !dialog.isShowing()) {
            dialog.show();
        }
    }

    public static MaterialDialog creatBaseDialog(Context context, String title, String content) {
        return new MaterialDialog.Builder(context)
                .title(title)
                .content(content)
                .positiveText(R.string.confirm)
                .positiveColor(AndroidUtils.getColor(context, R.color.f))
                .negativeColor(AndroidUtils.getColor(context, R.color.f))
                .build();
    }

    public static MaterialDialog creatBaseNoTitleDialog(Context context, String content, String positiveText, String negativeText) {
        return new MaterialDialog.Builder(context)
                .content(content)
                .positiveText(positiveText)
                .negativeText(negativeText)
                .positiveColor(AndroidUtils.getColor(context, R.color.f))
                .negativeColor(AndroidUtils.getColor(context, R.color.f))
                .build();
    }

    public static MaterialDialog creatBaseDialog(Context context, String title, String content, String positiveText, String negativeText) {
        return new MaterialDialog.Builder(context)
                .title(title)
                .content(content)
                .positiveText(positiveText)
                .negativeText(negativeText)
                .positiveColor(AndroidUtils.getColor(context, R.color.f))
                .negativeColor(AndroidUtils.getColor(context, R.color.f))
                .build();
    }
}
